﻿//
// Copyright (c) 2024 BPer
//

#ifndef BPERUTIL_BUFFER_BPERBUFFER_H_
#define BPERUTIL_BUFFER_BPERBUFFER_H_
#include <bperutil/sys/BPerThread.h>
#include <bperutil/BPerType.h>
#include <bperutil/BPerAvType.h>
#define bPer_reindex(p)  if(p!=NULL) p->resetIndex();

class BPerMediaBuffer {
public:
	BPerMediaBuffer();
	virtual ~BPerMediaBuffer();
public:
	int32_t m_mediaType;
	int32_t m_uid;
	void resetIndex();
        uint32_t size();
protected:
	uint32_t m_putIndex;
	uint32_t m_getIndex;
	uint32_t m_cache_num;
	uint32_t m_size;
	uint32_t m_nextIndex;
	int32_t m_ret;
	BPerFrame** m_frames;
	BPerBufferManager* m_bufferManager;
protected:
	void initFrames(int pnum,int unitsize);

	void putFrame(BPerFrame* pframe);
	void getFrame(BPerFrame* pframe);
	BPerFrame* getCurFrameRef();
	int64_t getNextFrameTimestamp();
	uint8_t* getFrameRef(BPerFrame* pframe);
private:
	bPer_thread_mutex_t m_lock;
};

#endif /* BPERUTIL_BUFFER_BPERBUFFER_H_ */
